<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<meta http-equiv="Pragma" content="no-cache" />
	<title>个人资料</title>
	<link rel="stylesheet" href="css/weui.min.css" />
	<link rel="stylesheet" href="fonts/iconfont.css" />
	<link rel="stylesheet" href="css/style.css" />
	<script src="js/jquery-2.2.3.min.js"></script>

</head>
<style>
	.popup {
		opacity: 1;
		display: none;
	}

	.popup-content-bg {
		position: fixed;
		height: 100%;
		width: 100%;
		top: 0px;
		left: 0px;
		z-index: 4;
		background: #ccc;
		/* filter: blur(28px); */
		opacity: 0.77;
	}

	.popup-content {
		position: fixed;
		top: 137px;
		left: 50%;
		z-index: 9;
		width: 240px;
		height: 268px;
		margin: 0px 0px 0px -120px;
		background: #fff;
		border-radius: 20px;
		box-shadow: 1px 1px 10px rgba(32, 160, 255, 0.5);
		opacity: 1;
	}

	.popup-content img {
		margin: 41px 0px 0px 30px;
	}

	.weui-loadmore {
		width: 100%;
		height: 100%;
		font-size: 14px;
		text-align: center;
		position: absolute;
		background: #fff;
		z-index: 999;
		color: #fff;
		margin: 0px;
		line-height: 300px;
	}

	.weui-loading {
		width: 40px;
		height: 40px;
	}
</style>

<body ontouchstart>
	<div class="loading" style="display:none;">
		<div class="weui-loadmore">
			<i class="weui-loading"></i>
		</div>
	</div>
	<div class="weui-content">
		<div class="weui-cells">
			<div class="weui-cell">
				<div class="weui-cell__bd"><label class="weui-label">姓名</label></div>
				<div class="weui-cell__ft" id="name"></div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__bd"><label class="weui-label">性别</label></div>
				<div class="weui-cell__ft" id="sex"></div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__bd"><label class="weui-label">手机</label></div>
				<div class="weui-cell__ft" id="phone"></div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__bd"><label class="weui-label">邮箱</label></div>
				<div class="weui-cell__ft" id="email"></div>
			</div>
			<div class="weui-cell">
				<div class="weui-cell__bd"><label class="weui-label">公司</label></div>
				<!-- joinCompany.html -->
				<div class="weui-cell__ft" id="companyBox"><a href="#" class="blur-color" id="company"></a></div>
			</div>
			<!-- address.html 收货地址 -->
			<a href="#" class="weui-cell weui-cell_access">
				<div class="weui-cell__bd">收货地址管理</div>
				<div class="weui-cell__ft"></div>
			</a>


		</div>
		<div class="weui-cells">
			<a href="editinfo.html" class="weui-cell weui-cell_access">
				<div class="weui-cell__bd text-center"><i class="iconfont icon-write"></i> 修改资料</div>
			</a>
		</div>
		<!-- 点击加入公司弹窗 -->
		<div class="popup">
			<div class="popup-content-bg"></div>
			<div class="popup-content">
				<img src="./images/weijiarugongs_tubiao@2x.png" alt="">
				<div style="width:128px;height:17px;font-size:12px;line-height:17px;color:rgba(159,159,159,1);margin: 22px 0px 0px 56px;">请联系管理员
					加入公司</div>
				<div id="closePopup" style="width:103px;height:26px;background:rgba(32,160,255,1);text-align: center;border-radius:8px;opacity:1;font-size:12px;line-height:26px;color:rgba(255,255,255,1);margin: 19px auto 0px auto;">
					知道了
				</div>
			</div>
		</div>
	</div>
	<script src="./api.js"></script>
	<script>

		window.onload = function () {
			$('.loading').css('display', 'block');
			let api = getApi()

			//获取本地缓存的用户信息
			let userinfo = JSON.parse(localStorage.getItem('wxUserInfo')).data
			let token = userinfo.token
			let customerID = userinfo.customer.customerID

			// 回显个人资料
			fetch(api + '/customer/' + customerID, {
				method: "get",
				headers: {
					'Content-type': 'application/json',
					"Authorization": token
				}
			})
				.then(res => {
					if (res.status == 401) {
						alert('token过期，请重新登录')
						location.href = './index.html';
					}
					return res;
				})
				.then(res => res.json())
				.then((data) => {
					let userInfo = data.data
					$('.loading').css('display', 'none');
					userInfo.customerName ? $('#name').text(userInfo.customerName) : $('#name').text('--')
					userInfo.gender ? $('#sex').text(userInfo.gender) : $('#sex').text('--')
					userInfo.phoneNumber ? $('#phone').text(userInfo.phoneNumber) : $('#phone').text('--')
					userInfo.email ? $('#email').text(userInfo.email) : $('#email').text('--')
					if (userInfo.enterpriseName != null) {
						$('#companyBox').html(userInfo.enterpriseName)
					} else {
						$('#company').html('去加入')
					}
				}).catch((err) => {
					// window.location.href = './index.html'
				})

			//点击加入公司时弹窗
			$('#company').on('click', function () {
				$('.popup').css('display', 'block')
				$('#closePopup').click(function () {
					$('.popup').css('display', 'none')
				})
				$('.popup-content-bg').click(function () {
					$('.popup').css('display', 'none')
				})
			})
		}

	</script>
</body>

</html>